<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
     
  
 
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:cour:add']"
        >新增所选教师</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="courList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="学号" align="center" prop="stuId" />
      <el-table-column label="姓名" align="center" prop="stuName" />
      <el-table-column label="兴趣1" align="center" prop="interestOne" />
      <el-table-column label="兴趣2" align="center" prop="interestTwo" />
      <el-table-column label="兴趣3" align="center" prop="interestThree" />
     
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:cour:edit']"
          >添加/修改兴趣</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)" 
            v-hasPermi="['system:cour:edit']"
          >教师详情</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 新增选择教师  多选选项框 未完成 这里要填充所选教师的名单，这个名单是根据用户的兴趣来的，本界面只显示当前登录用户的兴趣爱好（姓名+教授科目）-->
    <el-dialog :title="title" :visible.sync="openee" width="400px" append-to-body>
      <el-select v-model="value1" multiple placeholder="请选择" style="margin-left: 70px;">
    <el-option 
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    
    <!-- 修改兴趣对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="兴趣一" prop="interestOne">
          <el-input v-model="form.interestOne" placeholder="请输入您的兴趣趋向" />
        </el-form-item>
        <el-form-item label="兴趣二" prop="interestTwo">
          <el-input v-model="form.interestTwo" placeholder="请输入您的兴趣趋向" />
        </el-form-item>
        <el-form-item label="兴趣三" prop="interestThree">
          <el-input v-model="form.interestThree" placeholder="请输入您的兴趣趋向" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCour, getCour, delCour, addCour, updateCour } from "@/api/system/cour";


export default {
  name: "Cour",
  data() {
    return {
      options: [],
      teacher:[],
      value1: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      courList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      openee:false,
      user: {},
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuId: null,
        stuName: null,
        interestOne: null,
        interestTwo: null,
        interestThree: null,
        determine: null,
        teacherId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
      // 表单重置
      reset() {
      this.form = {
        id: null,
        stuId: null,
        stuName: null,
        interestOne: null,
        interestTwo: null,
        interestThree: null,
        determine: null,
        teacherId: null
      };
      this.resetForm("form");
    },
// 写一个根据本页面用户id查询的兴趣，所查询的老师的数组
//     getTeacher(){
//       teacherList(this.queryParams).then(response => {
//         ?
// },



    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listCour(this.queryParams).then(response => {
        this.courList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log(this.courList);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
  
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openee = true;
      this.title = "添加选修教师";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      console.log(row);
      const id = row.id || this.ids
      getCour(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改选修兴趣";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCour(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCour(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + ids + '"的数据项？').then(function() {
        return delCour(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/cour/export', {
        ...this.queryParams
      }, `cour_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
